<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<style>
	body,html{
		margin: 0 auto;
		height:100%;
		width:100%;
		overflow:hidden;
		background: #D2E0F2;
	}
</style>
</head>
<body>
	<div id="system_User" style="width:100%;height:100%;" class="divfrist">
						<div style="width:100%;height:0.7%;overflow:hidden;"></div>
						<div style="width:100%;height:98.5%;">
								<div style="width:0.4%;height:100%;float:left;overflow:hidden;"></div>
								<div style="width:99.2%;height:100%;float:left;">
									 <div class="allborder" style="overflow: auto;height:100%;max-height:100%;">
										<!--内容区 -->
											<div style="width:100%;height:100%;">		
													 <table  id="UserTable" border="false"></table>
											</div>
											<div id="User_tb" style="overflow: hidden; padding-left: 10px; padding-top: 5px;padding-bottom: 5px;">
												 <a href="javascript:void(0);" class="easyui-linkbutton"   data-options="iconCls:'icon-add',plain:true" onclick="window.User.addUser()">增加用户</a>||	
												 <a href="javascript:void(0);" class="easyui-linkbutton"   data-options="iconCls:'icon-edit',plain:true" onclick="window.User.updateUser()">编辑用户</a>||
												 <a href="javascript:void(0);" class="easyui-linkbutton"   data-options="iconCls:'icon221',plain:true" onclick="window.User.addUser_role()">附加角色</a>||
												 <a href="javascript:void(0);" class="easyui-linkbutton"   data-options="iconCls:'icon222',plain:true" onclick="window.User.addUserDepartment()">附加部门</a>||
												 <a href="javascript:void(0);" class="easyui-linkbutton"   data-options="iconCls:'icon223',plain:true" onclick="window.User.addUser_Area()">附加区域</a>||
												 <a href="javascript:void(0);" class="easyui-linkbutton"   data-options="iconCls:'icon225',plain:true" onclick="window.User.addUser_Power()">特别授权</a>||
												 <a href="javascript:void(0);" class="easyui-linkbutton"   data-options="iconCls:'icon-no',plain:true" onclick="window.User.deleteUser ()">删除用户</a>||												 
												 <a href="javascript:void(0);" class="easyui-linkbutton"   data-options="iconCls:'icon-ok',plain:true" onclick="window.User.enableUser(1)">启用用户</a>||
												 <a href="javascript:void(0);" class="easyui-linkbutton"   data-options="iconCls:'icon482',plain:true" onclick="window.User.enableUser(0)">禁用用户</a>||
												 <input type="text" id="userNameNuber"> <a href="javascript:void(0);" class="easyui-linkbutton"   data-options="iconCls:'icon486',plain:true" onclick="window.User.selectUser()">查询用户</a>||	    	
											</div>		
													<!--内容区 -->
									 </div>
								</div>
								<div class="width:0.3%;height:100%;float:left;overflow:hidden;"></div>
						</div>
						<div class="width:100%;height:0.6%;overflow:hidden;"></div>
	</div>
</body>
<script type="text/javascript">
(function(){
	//增加用户
	function addUser(){
		$('<div id="User_addUser"></div>').window({
		    title: '增加用户', 		
		    iconCls:'icon-add', 
		    width:650,   
		    height:400,   
		    resizable:true,
		    closed: true,   
		    draggable:false,
		    modal: true,
		    content:$('<div style="width:100%;height:100%;"></div>').load("${pageContext.request.contextPath}/html/system/user_add.jsp"),
		    onClose:function(){
				$("#User_addUser").window("destroy",true);
				initUserdate();
		    }
		});
		$("#User_addUser").window("open");
		
	}
	//增加用户角色
	function addUser_role(){
		var rows = $("#UserTable").datagrid("getSelections");
		if(rows.length>1){
			alert("附加只能进行一行数据的操作");
			return;
		}
		if(rows.length<=0){
			alert("没有选中数据");
			return;
		}
		if($("#addUser_role").length>0){
			$("#addUser_role").window("open");
		}
		$('<div id="addUser_role"></div>').window({
		    title: '增加用户角色', 		
		    iconCls:'icon-add', 
		    width:600,   
		    height:400,   
		    resizable:true,
		    closed: true,   
		    draggable:false,
		    modal: true,
		    content:$('<div style="width:100%;height:100%;"></div>').load("${pageContext.request.contextPath}/html/system/user_role.jsp?sysUserId="+rows[0].sysUserId),
		    onClose:function(){
				$("#addUser_role").window("destroy",true);
				initUserdate();
		    }
		});
		$("#addUser_role").window("open");
	}
	//更新一个用户
	function updateUser(){
		
		var rows = $("#UserTable").datagrid("getSelections");
		if(rows.length>1){
			alert("更新只能进行一行数据的操作");
			return;
		}
		if(rows.length<=0){
			alert("没有选中数据");
			return;
		}
		if($("#User_updateUser").length>0){
			$("#User_updateUser").window("open");
		}
		$('<div id="User_updateUser"></div>').window({
		    title: '更新用户', 		
		    iconCls:'icon-add', 
		    width:650,   
		    height:400,   
		    resizable:true,
		    closed: true,   
		    draggable:false,
		    modal: true,
		    content:$('<div style="width:100%;height:100%;"></div>').load("${pageContext.request.contextPath}/html/system/user_add.jsp?sysUserId="+rows[0].sysUserId),
		    onClose:function(){
				$("#User_updateUser").window("destroy",true);
		    }
		});
		$("#User_updateUser").window("open");
		
	}
	//创建用户table
	function createUserTable(){
			$('#UserTable').datagrid({
				fit: true,
				toolbar:"#User_tb",
				singleSelect:false,
				rownumbers: true,
				animate:true,
				striped: true,
				loadMsg:'正在加载数据',
				collapsible:true,
				url:'${pageContext.request.contextPath}/sys/sysUserAction!getAllUser.action',
				idField:'sysUserId',
				fitColumns:true,
				columns:[[
				    {field:'sysUserId',checkbox:true,width:50},	
			  		{field:'sysUserName',title:'用户名称',width:120},
			  		{field:'sysUserRealyName',title:'用户本名',width:120},
			  		{field:'sysUserPwd',title:'用户密码',width:120},
			  		{field:'sysUserType',title:'用户类型',width:120},
			  		{field:'sysUserTell',title:'用户电话',width:120},
			  		{field:'sysUserNumber',title:'用户工号',width:120},
			  		{field:'sysUserSelfID',title:'用户身份证',width:120},
			  		{field:'sysUserEmail',title:'用户邮件',width:120},
			  		{field:'sysUserState',title:'用户状态',formatter : function(value, row, index){
			  		
						if(row.sysUserState=="0"){
							return  '<font color="red">禁用</font>';
						}
						if(row.sysUserState=="1"){
							return  '<font color="green">启用</font>';
						}
						return "";
						},width:120},
			  		{field:'sysUserCreateDate',title:'创建时间',width:120}
			  		]],
					pagination:true,
					
				});
	}
	//二次查询下面的下一页上一页
	function initUserdate(){
		var a = $("#userNameNuber").val();
		$('#UserTable').datagrid('reload',{
			sysUserName: a,
			sysUserNumber: a
		});
	}
	//查询当前第一页
	function selectUser(){	
		var a = $("#userNameNuber").val();
		$('#UserTable').datagrid('load',{
			sysUserName: a,
			sysUserNumber: a
		});
	}
	//删除用户
	function deleteUser(){
		var rows = $("#UserTable").datagrid("getSelections");
		if(rows.length<=0){
			alert("没有选中数据");
			return;
		}
		$.messager.confirm('提示', '你确定要删除这些数据吗?', function(r){
			if (r){
				$.ajax({
					   type: "POST",
					   url:'${pageContext.request.contextPath}/sys/sysUserAction!deleteUser.action',
					   data: {rows1:obj2str(rows)},
					   success: function(msg){
					   		if(msg=="success"){
					   			alert("删除成功");
					   			initUserdate();
					   		}else{
					   			alert("删除失败");
					   		}
					   },
					   error:function(a,b,c){
						   alert("查询失败");
					   }
				});	 
			}
		});
	}
	//启用禁用角色
	function enableUser(sysUserState){
		var rows = $("#UserTable").datagrid("getSelections");
		if(rows.length<=0){
			alert("没有选中数据");
			return;
		}
		$.ajax({
					   type: "POST",
					   url:'${pageContext.request.contextPath}/sys/sysUserAction!enableUser.action',
					   data: {sysUserState:sysUserState,rows1:obj2str(rows)},
					   success: function(msg){
					   		if(msg=="success"){
					   			alert("操作成功");
					   			initUserdate();
					   		}else{
					   			alert("操作失败");
					   		}
					   },
					   error:function(a,b,c){
						   alert("查询失败");
					   }
		});	 
	}
	//附加部门
	function addUserDepartment(){
		var rows = $("#UserTable").datagrid("getSelections");
		if(rows.length>1){
			alert("附加只能进行一行数据的操作");
			return;
		}
		if(rows.length<=0){
			alert("没有选中数据");
			return;
		}
		if($("#addUserDepartment").length>0){
			$("#addUserDepartment").window("open");
		}
		$('<div id="addUserDepartment"></div>').window({
		    title: '增加用户部门', 		
		    iconCls:'icon-add', 
		    width:600,   
		    height:400,   
		    resizable:true,
		    closed: true,   
		    draggable:false,
		    modal: true,
		    content:$('<div style="width:100%;height:100%;"></div>').load("${pageContext.request.contextPath}/html/system/user_department.jsp?sysUserId="+rows[0].sysUserId),
		    onClose:function(){
				$("#addUserDepartment").window("destroy",true);
				initUserdate();
		    }
		});
		$("#addUserDepartment").window("open");
		
		
	}
	//附加区域
	function addUser_Area(){
		var rows = $("#UserTable").datagrid("getSelections");
		if(rows.length>1){
			alert("附加只能进行一行数据的操作");
			return;
		}
		if(rows.length<=0){
			alert("没有选中数据");
			return;
		}
		if($("#addUserArea").length>0){
			$("#addUserArea").window("open");
		}
		$('<div id="addUserArea"></div>').window({
		    title: '增加用户区域', 		
		    iconCls:'icon-add', 
		    width:600,   
		    height:400,   
		    resizable:true,
		    closed: true,   
		    draggable:false,
		    modal: true,
		    content:$('<div style="width:100%;height:100%;"></div>').load("${pageContext.request.contextPath}/html/system/user_area.jsp?sysUserId="+rows[0].sysUserId),
		    onClose:function(){
				$("#addUserArea").window("destroy",true);
				initUserdate();
		    }
		});
		$("#addUserArea").window("open");
	}
	//附加区域
	function addUser_Power(){
		var rows = $("#UserTable").datagrid("getSelections");
		if(rows.length>1){
			alert("附加只能进行一行数据的操作");
			return;
		}
		if(rows.length<=0){
			alert("没有选中数据");
			return;
		}
		if($("#addUser_Power").length>0){
			$("#addUser_Power").window("open");
		}
		$('<div id="addUser_Power"></div>').window({
		    title: '增加用户权限', 		
		    iconCls:'icon-add', 
		    width:600,   
		    height:400,   
		    resizable:true,
		    closed: true,   
		    draggable:false,
		    modal: true,
		    content:$('<div style="width:100%;height:100%;"></div>').load("${pageContext.request.contextPath}/html/system/user_power.jsp?sysUserId="+rows[0].sysUserId),
		    onClose:function(){
				$("#addUser_Power").window("destroy",true);
				initUserdate();
		    }
		});
		$("#addUser_Power").window("open");
	}
	//注册所有事件
	window["User"]={};
	window["User"]["addUser"]=addUser;
	window["User"]["updateUser"]=updateUser;
	window["User"]["initUserdate"]=initUserdate;
	window["User"]["selectUser"]=selectUser;
	window["User"]["deleteUser"]=deleteUser;
	window["User"]["enableUser"]=enableUser;
	window["User"]["addUser_role"]=addUser_role;
	window["User"]["addUserDepartment"]=addUserDepartment;
	window["User"]["addUser_Area"]=addUser_Area;
	window["User"]["addUser_Power"]=addUser_Power;
	$(function(){	
		$.parser.parse('#system_User'); 
		$('#userNameNuber').validatebox({   
		    required: true,   
		    validType: ["unnormal","length[0,15]"] 
		});
		 createUserTable();
	});
})();
</script>
</html>